import { Column, Entity, PrimaryColumn,  JoinColumn, OneToOne } from 'typeorm';
import { TeamEntity } from './team.entity';
import { StudentEntity } from './user/student.entity';

@Entity('team_student', {
  comment: '队伍学生关联表',
  schema: 'public',
})
export class StudentTeamEntity {
  @PrimaryColumn({
    type: 'integer',
    name: 'student_id',
    comment: '学生id',
  })
  studentId: number;
  @PrimaryColumn({
    type: 'integer',
    name: 'team_id',
    comment: '队伍id',
  })
  teamId: number;

  @Column({
    type: 'character',
    name: 'is_leader',
    default: 0,
    comment: '是否为队长（0为队员，1为队长）',
  })
  isLeader: string;

  @OneToOne(() => TeamEntity, (team) => team.studentTeams)
  @JoinColumn({ name: 'team_id', referencedColumnName: 'teamId' })
  team: TeamEntity;

  @OneToOne(() => StudentEntity, (student) => student.studentTeam)
  @JoinColumn({ name: 'student_id', referencedColumnName: 'studentId' })
  student: StudentEntity;
}
